package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsIssue;
import com.qf.pojo.DtsOrder;
import com.qf.service.DtsAdminIssueService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/issue")
public class DtsAdminIssueController {

    @Autowired
    DtsAdminIssueService adminIssueService;

    @PostMapping("/delete")
    public Object delete(@RequestBody DtsIssue issue){
        adminIssueService.delete(issue);
        return ResponseUtil.ok();
    }

    @PostMapping("/create")
    public Object create(@RequestBody DtsIssue issue){
        DtsIssue dtsIssue = adminIssueService.insert(issue);
        return ResponseUtil.ok(dtsIssue);
    }

    @PostMapping("/update")
    public Object update(@RequestBody DtsIssue issue){
        adminIssueService.update(issue);
        return ResponseUtil.ok();
    }

    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(value = "limit",required = false,defaultValue = "10") Integer limit,
                       String sort, String order, String question){

        IPage<DtsIssue> iPage = adminIssueService.queryPage(page,limit,sort,order,question);
        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items", iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
